package top.zhangjianyong.tools.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import top.zhangjianyong.tools.utils.ApiResponse;

/**
 * @author ： zhangjianyong
 * @date ： 2021/11/1 15:46
 */
@Slf4j
//@Aspect
//@Component
//@Order(999)
public class ExceptionAspect {
    @Pointcut("execution(* top.zhangjianyong.tools.controller.*.*(..))")
    public void pointCut() {

    }

    @Around("pointCut()")
    public Object catchException(ProceedingJoinPoint pjp) {
        try {
            return pjp.proceed();
        } catch (Throwable e) {
            log.error(e.getMessage(), e);
            return ApiResponse.fail(e.getMessage());
        }
    }
}
